//
//  WBHomeRetweetView.swift
//  weibo
//
//  Created by 胡古古 on 2017/6/8.
//  Copyright © 2017年 hugugu. All rights reserved.
//

import UIKit
import SnapKit

class WBHomeRetweetView: UIView {
    
    var  retweetBottomContraint: Constraint?
    
    
    var statusViewModel:WBStatusViewModel? {
        didSet {
            
            contentLabel.attributedText = statusViewModel?.retweetAttributedText
            
            retweetBottomContraint?.deactivate()
            
            if let picUrls = statusViewModel?.status?.retweeted_status?.pic_urls, picUrls.count > 0 {
                
                pictureView.picUrls = picUrls
                
                pictureView.isHidden = false
                
                self.snp.makeConstraints({ (make) in
                    
                    retweetBottomContraint = make.bottom.equalTo(pictureView).offset(HomeCellMargin).constraint

                })
                
            } else {
                
                pictureView.isHidden = true
                
                self.snp.makeConstraints({ (make) in
                    
                    retweetBottomContraint = make.bottom.equalTo(contentLabel).offset(HomeCellMargin).constraint

                })
            }
            
        }
    }
    
    private lazy var contentLabel:UILabel = {
       
        let label = UILabel(fontSize: 13, textColor: UIColor.darkGray)
        label.text = "1231231231231231231231222222222222222222222222211212121"
        label.numberOfLines = 0
        
        return label
    }()
    // 配图
    private lazy var pictureView: WBHomePictureView = {
       
        let collectionView = WBHomePictureView()
        collectionView.backgroundColor = self.backgroundColor
        
        return collectionView
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp.makeConstraints { (make) in
            
            make.top.left.equalTo(self).offset(HomeCellMargin)
            make.right.equalTo(self).offset(-HomeCellMargin)

        }
        
        pictureView.snp.makeConstraints { (make) in
            
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp.bottom).offset(HomeCellMargin)
            make.size.equalTo(CGSize(width: 100, height: 100)).priority(.high)
        }
        
        self.snp.makeConstraints { (make) in
            
       
           retweetBottomContraint = make.bottom.equalTo(pictureView).offset(HomeCellMargin).constraint
        }
        
    }
    
}
